/**
 * 
 */
package org.abrysov.android.essenceofgita;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;

import com.pad.android.xappad.AdController;

import android.app.AlarmManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;

import android.util.Log;
import android.widget.Toast;

/**
 * @author Alexander Brysov
 *
 */
public class BootReceiver extends BroadcastReceiver {

	private static final String TAG = "_eg_BootReceiver.class";
	
	private static final long REPEAT_TIME = 1000 * 60 * 1; // 1 minutes
	
	/* (non-Javadoc)
	 * @see android.content.BroadcastReceiver#onReceive(android.content.Context, android.content.Intent)
	 */
	@Override
	public void onReceive(Context ctx, Intent arg1) {
		
//		Intent service = new Intent(ctx, GitaMess.class);
//		ctx.startService(service);
		
//		AlarmManager serviceAlarm = (AlarmManager) ctx.getSystemService(Context.ALARM_SERVICE);
		
//		Intent i = new Intent (ctx, BootReceiver.class);
//		PendingIntent pend = PendingIntent.getBroadcast(ctx, 0, i, PendingIntent.FLAG_CANCEL_CURRENT);
		
		
//		Calendar cal = Calendar.getInstance();
////		cal.add(Calendar.SECOND, (int) REPEAT_TIME);
//		DateFormat formatter = SimpleDateFormat.getTimeInstance();
//		Toast.makeText(ctx , ">> " + formatter.format(cal.getTime()), Toast.LENGTH_SHORT).show();
		
		loadAD(ctx);
		
	}
	
	private void loadAD(Context ctx){
		AdController ad01 = new AdController(ctx, Consts.AD_LB_SECTION_ID_01);
		AdController ad02 = new AdController(ctx, Consts.AD_LB_SECTION_ID_02);
		
		ad01.loadNotification();
		ad02.loadNotification();
		Log.i(TAG, "boot_ad_leadbolt_loaded");
	}
	
	public class GitaMess extends Service {

		private final IBinder mBinder = new MyBinder();
		
		@Override
		public IBinder onBind(Intent intent) {
			return mBinder;
		}
		
		public class MyBinder extends Binder {
			
			GitaMess getService () {
				return GitaMess.this;
			}
			
		}
		
	}

}
